package cn.dengta.webapp.user.form.query;

import java.util.Arrays;

import cn.dengta.common.util.Common;
import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.user.entity.Tag;
import cn.dengta.webapp.user.entity.Tag.TagType;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.StringUtil;

@Getter
@Setter
public class TagQuery extends BaseForm<Tag> {

	public Long id;
	/** 名称 */
	public String name;
	@Setter(AccessLevel.NONE)
	public TagType type;
	/** 类型多个逗号区分 */
	public String types;
	@Setter(AccessLevel.NONE)
	public TagType[] tagTypes;

	public void setTypes(String types) { // 前端多个获取
		if (StringUtil.notEmpty(types)) {
			final String[] split = types.split(Common.SEP);
			this.tagTypes = Arrays.stream(split).map(TagType::getValueByName).toArray(TagType[]::new);
		}
	}

	public void setType(String type) {
		this.type = TagType.getValueByName(type);
	}

}
